package org.novaacropole.util;

import javax.el.ELContext;
import javax.el.MethodExpression;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

public class FacesUtil {

	public static void next(ActionEvent actionEvent) {
		String next = (String) actionEvent.getComponent().getAttributes().get("next");
		String msg = (String) actionEvent.getComponent().getAttributes().get("msg");
		if (next != null) {
			next = "#{" + next + "}";
			FacesContext facesContext = FacesContext.getCurrentInstance();
			ELContext elContext = facesContext.getELContext();
			MethodExpression methodExpression = facesContext.getApplication().getExpressionFactory()
					.createMethodExpression(elContext, next, null, new Class<?>[0]);
			methodExpression.invoke(elContext, null);
		}
		if (msg != null)
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(msg));
	}

}
